package com.wtzz.police.base.config;

import com.github.dozermapper.core.DozerBeanMapperBuilder;
import com.github.dozermapper.core.Mapper;
import com.github.dozermapper.core.loader.api.BeanMappingBuilder;
import com.wtzz.police.base.bean.dto.UserDto;
import com.wtzz.police.base.bean.dto.UserInfoDto;
import com.wtzz.police.base.entity.User;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static com.github.dozermapper.core.loader.api.TypeMappingOptions.mapNull;

@Configuration
public class DozerConfig {

    @Bean
    public Mapper createDozerBeanMapper() {
        DozerBeanMapperBuilder builder = DozerBeanMapperBuilder.create();
        builder.withMappingBuilder(new BeanMappingBuilder() {
            @Override
            protected void configure() {
                mapping(User.class, UserDto.class, mapNull(false)).fields("department.id", "departmentId").fields("department.name", "departmentName");
            }
        });
        return builder.build();
    }

}
